from flask import Blueprint,jsonify,request,session
from utils.ipython.code_execute import codeExecute

# 创建一个名为 'admin' 的蓝图
code = Blueprint('code', __name__)

@code.route('/login')
def login():
    return "Admin Login Page"

# 删除用户的 InteractiveShell 实例
@code.route('/delete_user', methods=['POST'])
def delete_user():
    return jsonify(codeExecute.delete_shell(request.json.get('user_id', '')))


@code.route('/execute', methods=['POST'])
def execute():
    data = request.json
    user_id = data.get('user_id', '')

    if not user_id:
        return jsonify({'error': 'Missing user_id'}), 400
    
    code = data.get('code', '')

    return jsonify(codeExecute.execute_code(user_id, code))